﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ShareMarking.Systems.Service;
using System.Configuration;
using Common.Utilities.Excel;
using Common.Utilities.Excel.Import;
using System.Data;
using ShareMarking.Service;
using System.Text.RegularExpressions;
using ShareMarking.Entity;
using ShareMarking.Interface;
using System.Text;

namespace ShareMarking.Web.admin.EnterPrise.Activity
{
    public partial class WXCodeimport : ManagePage
    {
        private static string httpstr = ConfigurationManager.AppSettings["vigohttp"];
        private static string signsecret = ConfigurationManager.AppSettings["signscrect"];
        private static string diyhttp = ConfigurationManager.AppSettings["diyhttp"];//本系统网站域名
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        #region 微信二维码导入信息==================================

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                #region 初始化变量
                //获取文件路径
                var filepath = Server.MapPath(this.txt_upload.Text.Trim());
                ExcelUtilities util = new ExcelUtilities();
                Excel excel = null;
                //获取配置
                var result = util.ImportExcel(filepath, "wxcodeimport", out excel);
                bool result2 = false;
                bool result3 = false;
                bool result4 = false;
                bool result5 = false;
                int SuccessCount = 0;//成功条数
                int ErrorCount = 0;//失败条数
                #endregion

                #region 循环判断添加数据
                if (result.Result == ExcelResultType.Succeed)
                {

                    var datasource = excel.DataSet;
                    if (datasource.Tables.Count > 0)
                    {
                        foreach (DataRow row in datasource.Tables[0].Rows)
                        {


                            #region 循环判断更新或增加 2017-3-21
                            //string Par_A_Name = "";
                            //if (!row[3].ToString().IsNullOrEmpty())
                            //{
                            //    //if (Regex.Replace(row[1].ToString().Trim(), @"\s", "") != "" && Regex.Replace(row[0].ToString().Trim(), @"\s", "") != "")
                            //    //{
                            //    //    Par_A_Name= Regex.Replace(row[1].ToString().Trim(), @"\s", "") + "-" + Regex.Replace(row[0].ToString().Trim(), @"\s", "");
                            //    //}
                            //    //else if (Regex.Replace(row[0].ToString().Trim(), @"\s", "") != "")
                            //    //{
                            //    //    Par_A_Name = Regex.Replace(row[0].ToString().Trim(), @"\s", "");
                            //    //}
                            //    //else if (Regex.Replace(row[1].ToString().Trim(), @"\s", "") != "")
                            //    //{
                            //    //    Par_A_Name = Regex.Replace(row[1].ToString().Trim(), @"\s", "");
                            //    //}
                            //    if (Regex.Replace(row[3].ToString().Trim(), @"\s", "") != "")
                            //    {
                            //        Par_A_Name = Regex.Replace(row[3].ToString().Trim(), @"\s", "");
                            //    }
                            //    var qr_Activityentity = qr_ActivityService.Instance.Get_SingleEntity_byWhere(
                            //        qr_Activity._.A_Name == Par_A_Name
                            //        //&& qr_Activity._.A_currentUrl == Regex.Replace(row[7].ToString().Trim(), @"\s", "")
                            //        );
                            //    if (qr_Activityentity != null)//根据活动名称、URL判断是否添加，有相同名称、URL的活动，更新二维码，若更新失败就叠加到失败条数
                            //    {
                            //        #region  更新操作（不更新,只叠加错误条数）

                            //        #region 根据时间判断路径
                            //        var currenturl = "";
                            //        //string Par_A_Name = row[1].ToString().Trim() +"-"+ row[0].ToString().Trim();//名称-编号
                            //        //string Par_A_Name = "PNRPNE活动区域码-" + row[0].ToString().Trim() + "";

                            //        DateTime ParStartTime_diy = Convert.ToDateTime(row.ItemArray[4].ToString().Trim());//.ToString("yyyy-MM-dd HH:mm:ss")
                            //        DateTime ParEndTime_diy = Convert.ToDateTime(row.ItemArray[5].ToString().Trim());
                            //        if (DateTime.Now < ParStartTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[6].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_Diy_wxbeforeUrl;
                            //        }
                            //        else if (DateTime.Now > ParStartTime_diy && DateTime.Now < ParEndTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[7].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //        }
                            //        else
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[8].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //        }
                            //        #endregion

                            //        #region 单图文
                            //        var extra = new List<extra>() { 
                            //            //new extra { 
                            //            //    title = "解码萌宝成长礼，超多大奖送不停！", 
                            //            //    shortdesc = "解码萌宝成长礼，超多大奖送不停！", 
                            //            //    linkurl = (currenturl).Replace('&','$'),
                            //            //    picurl =diyhttp+ "/images/JiemaActivity.jpg" 
                            //            //}
                            //            new ShareMarking.Interface.extra { 
                            //                title = "美赞臣产品付费试用活动", 
                            //                shortdesc = "", 
                            //                linkurl = (currenturl).Replace('&','$'),
                            //                picurl =diyhttp+ "/images/20170524.jpg"
                            //            }
                            //        };

                            //        var message = new ShareMarking.Interface.message2()
                            //        {
                            //            id = qr_Activityentity.A_wxQrCodeID,
                            //            title = Par_A_Name,
                            //            remark = Par_A_Name + "的二维码",
                            //            sacode = "test",
                            //            extra = extra
                            //        };
                            //        #endregion

                            //        #region vigo接口申请
                            //        var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                            //        var resultentity = vigo.UpdateQrcode(message);
                            //        #endregion

                            //        #region 更新单图文活动
                            //        //var entity = new qr_Activity();
                            //        qr_Activityentity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                            //        qr_Activityentity.A_Desc = ""; //row[3].ToString().Trim();//活动描述
                            //        qr_Activityentity.A_Manager = row[2].ToString().Trim();//负责人
                            //        //qr_Activityentity.A_wxTitle = "解码萌宝成长礼，超多大奖送不停！";
                            //        //qr_Activityentity.A_wxImgUrl = diyhttp + "/images/JiemaActivity.jpg";//图片
                            //        //qr_Activityentity.A_wxDesc = "解码萌宝成长礼，超多大奖送不停！";
                            //        qr_Activityentity.A_wxTitle = "美赞臣产品付费试用活动";
                            //        qr_Activityentity.A_wxImgUrl = diyhttp + "/images/20170524.jpg";//图片
                            //        qr_Activityentity.A_wxDesc = "";
                            //        qr_Activityentity.A_wxUrl = row[7].ToString().Trim();//活动中链接;
                            //        qr_Activityentity.A_wxbeforeUrl = row[6].ToString().Trim();//活动前链接;
                            //        qr_Activityentity.A_wxafterUrl = row[8].ToString().Trim();//活动后链接;
                            //        qr_Activityentity.A_SaCode = "";
                            //        qr_Activityentity.A_StartTime = ParStartTime_diy;
                            //        qr_Activityentity.A_EndTime = ParEndTime_diy;
                            //        qr_Activityentity.A_currentUrl = currenturl;//当前使用的URL
                            //        qr_Activityentity.DateModified = DateTime.Now;
                            //        result5 = qr_ActivityService.Instance.Update_Entity(qr_Activityentity);
                            //        #endregion

                            //        ComLib.LogLib.Log4NetBase.Log("有相同重复活动名称：" + qr_Activityentity.A_Name);
                            //        if (result5)
                            //        {
                            //            SuccessCount += 1;
                            //            AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改qr_Activity:" + qr_Activityentity.ActivityID); //记录日志
                            //        }
                            //        else
                            //        {

                            //            ErrorCount += 1;//已经添加
                            //        }
                            //        #endregion
                            //    }
                            //    else
                            //    {
                            //        #region  增加操作 去掉数据源的空格和换行符

                            //        #region 根据时间判断路径
                            //        var currenturl = "";

                            //        DateTime ParStartTime_diy = Convert.ToDateTime(row.ItemArray[4].ToString().Trim());//.ToString("yyyy-MM-dd HH:mm:ss")
                            //        DateTime ParEndTime_diy = Convert.ToDateTime(row.ItemArray[5].ToString().Trim());
                            //        if (DateTime.Now < ParStartTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[6].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_Diy_wxbeforeUrl;
                            //        }
                            //        else if (DateTime.Now > ParStartTime_diy && DateTime.Now < ParEndTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[7].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //        }
                            //        else
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[8].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //        }
                            //        #endregion

                            //        #region 组装消息
                            //        var sceneid = 0;
                            //        qr_QrCodeType type = qr_QrCodeTypeService.Instance.Get_SingleEntity_byWhere(qr_QrCodeType._.QrCodeTypeID == 1000);
                            //        sceneid = type.QT_CurrentIndex.ConvertTo<int>() + 1;

                            //        #region 单图文
                            //        List<ShareMarking.Interface.extra> extra = new List<ShareMarking.Interface.extra>() { 
                            //            //new ShareMarking.Interface.extra { 
                            //            //    title = "解码萌宝成长礼，超多大奖送不停！", 
                            //            //    shortdesc = "解码萌宝成长礼，超多大奖送不停！", 
                            //            //    linkurl = (currenturl).Replace('&','$'),
                            //            //    picurl =diyhttp+ "/images/JiemaActivity.jpg"
                            //            //}
                            //            new ShareMarking.Interface.extra { 
                            //                title = "美赞臣产品付费试用活动", 
                            //                shortdesc = "", 
                            //                linkurl = (currenturl).Replace('&','$'),
                            //                picurl =diyhttp+ "/images/20170524.jpg"
                            //            }
                            //        };

                            //        #endregion

                            //        //string Par_A_Name = row[1].ToString().Trim() + "-" + row[0].ToString().Trim();//名称-编号
                            //        var message = new ShareMarking.Interface.message()
                            //        {
                            //            title = Par_A_Name,
                            //            remark = Par_A_Name + "的二维码",
                            //            sacode = "test",
                            //            scene_id = sceneid,
                            //            extra = extra
                            //        };
                            //        #endregion

                            //        #region vigo接口申请
                            //        var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                            //        var resultentity = vigo.CreateQrcode(message);
                            //        #endregion

                            //        #region 自增sceneid重新请求直到成功为止
                            //        while (resultentity.errcode == "12")
                            //        {
                            //            ComLib.LogLib.Log4NetBase.Log("错误信息:" + resultentity.errmsg + "/sceneid=" + sceneid);
                            //            sceneid += 1;
                            //            message.scene_id = sceneid;
                            //            resultentity = vigo.CreateQrcode(message);
                            //        }
                            //        #endregion

                            //        if (resultentity.errcode == "00")
                            //        {
                            //            string ActivityID = "";

                            //            #region 保存二维码到数据库
                            //            qr_QrCode qrcode = new qr_QrCode()
                            //            {
                            //                id = resultentity.message.id,
                            //                type = 1000,
                            //                scene_id = resultentity.message.scene_id,
                            //                sacode = resultentity.message.sacode,
                            //                title = resultentity.message.title,
                            //                remark = resultentity.message.remark,
                            //                code_url = resultentity.message.code_url,
                            //                qrcode_url = resultentity.message.qrcode_url,
                            //                addtime = resultentity.message.addtime,
                            //                status = resultentity.message.status,
                            //                isdelete = false
                            //            };
                            //            qr_QrCodeService.Instance.Add_Entity(qrcode);
                            //            #endregion

                            //            #region 保存单图文活动
                            //            var entity = new qr_Activity();
                            //            entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                            //            entity.A_Desc = "美赞臣产品付费试用活动";//row[3].ToString().Trim();//活动描述
                            //            entity.A_Manager = row[2].ToString().Trim();//负责人
                            //            entity.A_wxQrCodeID = resultentity.message.id.ToString();
                            //            entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                            //            //entity.A_wxTitle = "解码萌宝成长礼，超多大奖送不停！";
                            //            //entity.A_wxImgUrl = diyhttp + "/images/JiemaActivity.jpg";//图片
                            //            //entity.A_wxDesc = "解码萌宝成长礼，超多大奖送不停！";
                            //            entity.A_wxTitle = "美赞臣产品付费试用活动";
                            //            entity.A_wxImgUrl = diyhttp + "/images/20170524.jpg";//图片
                            //            entity.A_wxDesc = "";
                            //            entity.A_wxUrl = row[7].ToString().Trim();//活动中链接;
                            //            entity.A_wxbeforeUrl = row[6].ToString().Trim();//活动前链接;
                            //            entity.A_wxafterUrl = row[8].ToString().Trim();//活动后链接;
                            //            entity.A_SaCode = "";
                            //            entity.A_StartTime = ParStartTime_diy;
                            //            entity.A_EndTime = ParEndTime_diy;
                            //            entity.CreateOn = DateTime.Now;
                            //            entity.isneedupdate = false;
                            //            entity.A_currentUrl = currenturl;//当前时间的currurl
                            //            entity.isSenate = 1;//有参标识
                            //            entity.A_RuleText = "AMN活动";//标识活动，导出图片可筛选
                            //            result2 = qr_ActivityService.Instance.Add_Entity(entity);
                            //            ActivityID = entity.ActivityID.ToString();
                            //            #endregion

                            //            #region 添加关联
                            //            qr_QrCodeRelate qrrelate = new qr_QrCodeRelate()
                            //            {
                            //                qr_Type = 1000,//1000是活动
                            //                qr_CodeID = resultentity.message.id,
                            //                qr_Scene_ID = resultentity.message.scene_id,
                            //                rel_Code = ActivityID,
                            //                IsDelete = false,
                            //                CreateOn = DateTime.Now
                            //            };
                            //            result3 = qr_QrCodeRelateService.Instance.Add_Entity(qrrelate);
                            //            #endregion

                            //            #region 更改二维码类型表
                            //            type.QT_CurrentIndex = sceneid;
                            //            type.QT_Used = type.QT_Used + 1;
                            //            type.QT_Surplus = type.QT_Surplus - 1;
                            //            result4 = qr_QrCodeTypeService.Instance.Update_Entity(type);
                            //            #endregion
                            //        }
                            //        if (result2 && result3 && result4)
                            //        {
                            //            SuccessCount += 1;
                            //        }
                            //        else
                            //        {
                            //            ErrorCount += 1;//已经添加
                            //        }
                            //        #endregion
                            //    }
                            //}
                            //else
                            //{
                            //    ErrorCount += 1;//失败条数
                            //}
                            #endregion

                            #region 循环判断更新或增加 2017-12-01 南区红包活动
                            if (!row[0].ToString().IsNullOrEmpty())
                            {
                                //string Par_A_Name = Regex.Replace(row[1].ToString().Trim(), @"\s", "") + "-" + Regex.Replace(row[0].ToString().Trim(), @"\s", "");
                                string Par_A_Name = Regex.Replace(row[3].ToString().Trim(), @"\s", "");
                                var qr_Activityentity = qr_ActivityService.Instance.Get_SingleEntity_byWhere(
                                    qr_Activity._.A_Name == Par_A_Name
                                    && qr_Activity._.A_currentUrl == Regex.Replace(row[7].ToString().Trim(), @"\s", "")
                                    );
                                if (qr_Activityentity != null)//根据活动名称、URL判断是否添加，有相同名称、URL的活动，更新二维码，若更新失败就叠加到失败条数
                                {
                                    #region  更新操作（不更新,只叠加错误条数）

                                    #region 根据时间判断路径
                                    var currenturl = "";
                                    //string Par_A_Name = row[1].ToString().Trim() +"-"+ row[0].ToString().Trim();//名称-编号
                                    //string Par_A_Name = "PNRPNE活动区域码-" + row[0].ToString().Trim() + "";

                                    DateTime ParStartTime_diy = Convert.ToDateTime(row.ItemArray[4].ToString().Trim());//.ToString("yyyy-MM-dd HH:mm:ss")
                                    DateTime ParEndTime_diy = Convert.ToDateTime(row.ItemArray[5].ToString().Trim());
                                    if (DateTime.Now < ParStartTime_diy)
                                    {
                                        currenturl = Regex.Replace(row.ItemArray[6].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_Diy_wxbeforeUrl;
                                    }
                                    else if (DateTime.Now > ParStartTime_diy && DateTime.Now < ParEndTime_diy)
                                    {
                                        currenturl = Regex.Replace(row.ItemArray[7].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                                    }
                                    else
                                    {
                                        currenturl = Regex.Replace(row.ItemArray[8].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                                    }
                                    #endregion

                                    #region 单图文
                                    var extra = new List<extra>() { 
                                        //new extra { 
                                        //    title = "解码萌宝成长礼，超多大奖送不停！", 
                                        //    shortdesc = "解码萌宝成长礼，超多大奖送不停！", 
                                        //    linkurl = (currenturl).Replace('&','$'),
                                        //    picurl =diyhttp+ "/images/JiemaActivity.jpg" 
                                        //}
                                        new ShareMarking.Interface.extra { 
                                            title = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", ""),
                                            shortdesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", ""), 
                                            linkurl = HttpUtility.UrlDecode((currenturl).Replace('&','$'), Encoding.UTF8),//HttpUtility.UrlDecode((currenturl).Replace('&','$'), Encoding.UTF8),
                                            picurl =diyhttp+ Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "")//"/images/red.jpg"
                                        }
                                    };

                                    var message = new ShareMarking.Interface.message2()
                                    {
                                        id = qr_Activityentity.A_wxQrCodeID,
                                        title = Par_A_Name,
                                        remark = Par_A_Name + "的二维码",
                                        sacode = "test",
                                        extra = extra
                                    };
                                    #endregion

                                    #region vigo接口申请
                                    var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                                    var resultentity = vigo.UpdateQrcode(message);
                                    #endregion

                                    #region 更新单图文活动
                                    //var entity = new qr_Activity();
                                    qr_Activityentity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                                    qr_Activityentity.A_Desc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", ""); //row[3].ToString().Trim();//活动描述
                                    qr_Activityentity.A_Manager = row[2].ToString().Trim();//负责人
                                    qr_Activityentity.A_wxTitle = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", "");//"美赞臣产品付费试用活动";
                                    qr_Activityentity.A_wxImgUrl = diyhttp + Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "");//"/images/20170524.jpg";//图片
                                    qr_Activityentity.A_wxDesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", "");
                                    qr_Activityentity.A_wxUrl = row[7].ToString().Trim();//活动中链接;
                                    qr_Activityentity.A_wxbeforeUrl = row[6].ToString().Trim();//活动前链接;
                                    qr_Activityentity.A_wxafterUrl = row[8].ToString().Trim();//活动后链接;
                                    qr_Activityentity.A_SaCode = "";
                                    qr_Activityentity.A_StartTime = ParStartTime_diy;
                                    qr_Activityentity.A_EndTime = ParEndTime_diy;
                                    qr_Activityentity.A_currentUrl = currenturl;//当前使用的URL
                                    qr_Activityentity.DateModified = DateTime.Now;
                                    result5 = qr_ActivityService.Instance.Update_Entity(qr_Activityentity);
                                    #endregion

                                    ComLib.LogLib.Log4NetBase.Log("有相同重复活动名称：" + qr_Activityentity.A_Name);
                                    if (result5)
                                    {
                                        SuccessCount += 1;
                                        AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改qr_Activity:" + qr_Activityentity.ActivityID); //记录日志
                                    }
                                    else
                                    {

                                        ErrorCount += 1;//已经添加
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region  增加操作 去掉数据源的空格和换行符

                                    #region 根据时间判断路径
                                    var currenturl = "";

                                    DateTime ParStartTime_diy = Convert.ToDateTime(row.ItemArray[4].ToString().Trim());//.ToString("yyyy-MM-dd HH:mm:ss")
                                    DateTime ParEndTime_diy = Convert.ToDateTime(row.ItemArray[5].ToString().Trim());
                                    if (DateTime.Now < ParStartTime_diy)
                                    {
                                        currenturl = Regex.Replace(row.ItemArray[6].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_Diy_wxbeforeUrl;
                                    }
                                    else if (DateTime.Now > ParStartTime_diy && DateTime.Now < ParEndTime_diy)
                                    {
                                        currenturl = Regex.Replace(row.ItemArray[7].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                                    }
                                    else
                                    {
                                        currenturl = Regex.Replace(row.ItemArray[8].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                                    }
                                    #endregion

                                    #region 组装消息
                                    var sceneid = 0;
                                    qr_QrCodeType type = qr_QrCodeTypeService.Instance.Get_SingleEntity_byWhere(qr_QrCodeType._.QrCodeTypeID == 1000);
                                    sceneid = type.QT_CurrentIndex.ConvertTo<int>() + 1;

                                    #region 单图文
                                    List<ShareMarking.Interface.extra> extra = new List<ShareMarking.Interface.extra>() { 
                                        //new ShareMarking.Interface.extra { 
                                        //    title = "解码萌宝成长礼，超多大奖送不停！", 
                                        //    shortdesc = "解码萌宝成长礼，超多大奖送不停！", 
                                        //    linkurl = (currenturl).Replace('&','$'),
                                        //    picurl =diyhttp+ "/images/JiemaActivity.jpg"
                                        //}
                                        new ShareMarking.Interface.extra { 
                                            title = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", ""),
                                            shortdesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", ""), 
                                            linkurl = HttpUtility.UrlDecode((currenturl).Replace('&','$'), Encoding.UTF8),//HttpUtility.UrlDecode((currenturl).Replace('&','$'), Encoding.UTF8),
                                            picurl =diyhttp+ Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "")//"/images/20170524.jpg"
                                        }
                                    };

                                    #endregion

                                    //string Par_A_Name = row[1].ToString().Trim() + "-" + row[0].ToString().Trim();//名称-编号
                                    var message = new ShareMarking.Interface.message()
                                    {
                                        title = Par_A_Name,
                                        remark = Par_A_Name + "的二维码",
                                        sacode = "test",
                                        scene_id = sceneid,
                                        extra = extra
                                    };
                                    #endregion

                                    #region vigo接口申请
                                    var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                                    var resultentity = vigo.CreateQrcode(message);
                                    #endregion

                                    #region 自增sceneid重新请求直到成功为止
                                    while (resultentity.errcode == "12")
                                    {
                                        ComLib.LogLib.Log4NetBase.Log("错误信息:" + resultentity.errmsg + "/sceneid=" + sceneid);
                                        sceneid += 1;
                                        message.scene_id = sceneid;
                                        resultentity = vigo.CreateQrcode(message);
                                    }
                                    #endregion

                                    if (resultentity.errcode == "00")
                                    {
                                        string ActivityID = "";

                                        #region 保存二维码到数据库
                                        qr_QrCode qrcode = new qr_QrCode()
                                        {
                                            id = resultentity.message.id,
                                            type = 1000,
                                            scene_id = resultentity.message.scene_id,
                                            sacode = resultentity.message.sacode,
                                            title = resultentity.message.title,
                                            remark = resultentity.message.remark,
                                            code_url = resultentity.message.code_url,
                                            qrcode_url = resultentity.message.qrcode_url,
                                            addtime = resultentity.message.addtime,
                                            status = resultentity.message.status,
                                            isdelete = false
                                        };
                                        qr_QrCodeService.Instance.Add_Entity(qrcode);
                                        #endregion

                                        #region 保存单图文活动
                                        var entity = new qr_Activity();
                                        entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                                        entity.A_Desc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", "");//row[3].ToString().Trim();//活动描述
                                        entity.A_Manager = row[2].ToString().Trim();//负责人
                                        entity.A_wxQrCodeID = resultentity.message.id.ToString();
                                        entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                                        //entity.A_wxTitle = "解码萌宝成长礼，超多大奖送不停！";
                                        //entity.A_wxImgUrl = diyhttp + "/images/JiemaActivity.jpg";//图片
                                        //entity.A_wxDesc = "解码萌宝成长礼，超多大奖送不停！";
                                        entity.A_wxTitle = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", "");
                                        entity.A_wxImgUrl = diyhttp + Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "");//图片"/images/20170524.jpg"
                                        entity.A_wxDesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", "");
                                        entity.A_wxUrl = row[7].ToString().Trim();//活动中链接;
                                        entity.A_wxbeforeUrl = row[6].ToString().Trim();//活动前链接;
                                        entity.A_wxafterUrl = row[8].ToString().Trim();//活动后链接;
                                        entity.A_SaCode = "";
                                        entity.A_StartTime = ParStartTime_diy;
                                        entity.A_EndTime = ParEndTime_diy;
                                        entity.CreateOn = DateTime.Now;
                                        entity.isneedupdate = false;
                                        entity.A_currentUrl = currenturl;//当前时间的currurl
                                        entity.isSenate = 1;//有参标识
                                        entity.A_RuleText = "南区红包活动";//标识活动，导出图片可筛选
                                        result2 = qr_ActivityService.Instance.Add_Entity(entity);
                                        ActivityID = entity.ActivityID.ToString();
                                        #endregion

                                        #region 添加关联
                                        qr_QrCodeRelate qrrelate = new qr_QrCodeRelate()
                                        {
                                            qr_Type = 1000,//1000是活动
                                            qr_CodeID = resultentity.message.id,
                                            qr_Scene_ID = resultentity.message.scene_id,
                                            rel_Code = ActivityID,
                                            IsDelete = false,
                                            CreateOn = DateTime.Now
                                        };
                                        result3 = qr_QrCodeRelateService.Instance.Add_Entity(qrrelate);
                                        #endregion

                                        #region 更改二维码类型表
                                        type.QT_CurrentIndex = sceneid;
                                        type.QT_Used = type.QT_Used + 1;
                                        type.QT_Surplus = type.QT_Surplus - 1;
                                        result4 = qr_QrCodeTypeService.Instance.Update_Entity(type);
                                        #endregion
                                    }
                                    if (result2 && result3 && result4)
                                    {
                                        SuccessCount += 1;
                                    }
                                    else
                                    {
                                        ErrorCount += 1;//已经添加
                                    }
                                    #endregion
                                }
                            }
                            else
                            {
                                ErrorCount += 1;//失败条数
                            }
                            #endregion

                            #region 循环判断更新或增加 2017-7-14 mjn
                            //if (!row[0].ToString().IsNullOrEmpty())
                            //{
                            //    //string Par_A_Name = Regex.Replace(row[1].ToString().Trim(), @"\s", "") + "-" + Regex.Replace(row[0].ToString().Trim(), @"\s", "");
                            //    string Par_A_Name = Regex.Replace(row[3].ToString().Trim(), @"\s", "");
                            //    var qr_Activityentity = qr_ActivityService.Instance.Get_SingleEntity_byWhere(
                            //        qr_Activity._.A_Name == Par_A_Name
                            //        && qr_Activity._.A_currentUrl == Regex.Replace(row[7].ToString().Trim(), @"\s", "")
                            //        );
                            //    if (qr_Activityentity != null)//根据活动名称、URL判断是否添加，有相同名称、URL的活动，更新二维码，若更新失败就叠加到失败条数
                            //    {
                            //        #region  更新操作（不更新,只叠加错误条数）
                            //        var dt = qr_MoreActivityService.Instance.Get_Entity_byWhere_ToTable(qr_MoreActivity._.ActivityID == qr_Activityentity.ActivityID, qr_MoreActivity._.MA_Sort.Asc);
                            //        List<MoreActivity> alist = new List<MoreActivity>();
                            //        if (dt != null)
                            //        {
                            //            for (int i = 0; i < dt.Rows.Count; i++)
                            //            {
                            //                MoreActivity MoreActivity = new MoreActivity()
                            //                {
                            //                    ID = dt.Rows[i]["id"].ConvertTo<int>(),
                            //                    Sortnumber = dt.Rows[i]["MA_Sort"].ConvertTo<int>(),
                            //                };
                            //                alist.Add(MoreActivity);
                            //            }
                            //        }
                            //        #region 根据时间判断路径
                            //        var currenturl = "";
                            //        var currentur2 = "";
                            //        //string Par_A_Name = row[1].ToString().Trim() +"-"+ row[0].ToString().Trim();//名称-编号
                            //        //string Par_A_Name = "PNRPNE活动区域码-" + row[0].ToString().Trim() + "";

                            //        DateTime ParStartTime_diy = Convert.ToDateTime(row.ItemArray[4].ToString().Trim());//.ToString("yyyy-MM-dd HH:mm:ss")
                            //        DateTime ParEndTime_diy = Convert.ToDateTime(row.ItemArray[5].ToString().Trim());
                            //        if (DateTime.Now < ParStartTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[6].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_Diy_wxbeforeUrl;
                            //            currentur2 = Regex.Replace(row.ItemArray[12].ToString().Trim(), @"\s", "");
                            //        }
                            //        else if (DateTime.Now > ParStartTime_diy && DateTime.Now < ParEndTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[7].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //            currentur2 = Regex.Replace(row.ItemArray[13].ToString().Trim(), @"\s", "");
                            //        }
                            //        else
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[8].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //            currentur2 = Regex.Replace(row.ItemArray[14].ToString().Trim(), @"\s", "");
                            //        }
                            //        #endregion

                            //        #region 2图文
                            //        var extra = new List<extra>() { 
                            //            new ShareMarking.Interface.extra { 
                            //                title = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", ""),
                            //                shortdesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", ""), 
                            //                linkurl = HttpUtility.UrlDecode((currenturl).Replace('&','$'), Encoding.UTF8),//HttpUtility.UrlDecode((currenturl).Replace('&','$'), Encoding.UTF8),
                            //                picurl =diyhttp+ Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "")//"/images/20170524.jpg"
                            //            },
                            //            new ShareMarking.Interface.extra { 
                            //                title = Regex.Replace(row.ItemArray[15].ToString().Trim(), @"\s", ""),
                            //                shortdesc = Regex.Replace(row.ItemArray[16].ToString().Trim(), @"\s", ""), 
                            //                linkurl = HttpUtility.UrlDecode((currentur2).Replace('&','$'), Encoding.UTF8),
                            //                picurl =diyhttp+ Regex.Replace(row.ItemArray[17].ToString().Trim(), @"\s", "")//"/images/ar2.jpg"
                            //            }
                            //        };

                            //        var message = new ShareMarking.Interface.message2()
                            //        {
                            //            id = qr_Activityentity.A_wxQrCodeID,
                            //            title = Par_A_Name,
                            //            remark = Par_A_Name + "的二维码",
                            //            sacode = "test",
                            //            extra = extra
                            //        };
                            //        #endregion

                            //        #region vigo接口申请
                            //        var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                            //        var resultentity = vigo.UpdateQrcode(message);
                            //        #endregion
                            //        #region 更新多图文活动
                            //        if (alist.Count > 0)
                            //        {
                            //            for (int i = 0; i < alist.Count; i++)
                            //            {
                            //                if (alist[i].Sortnumber == 2)
                            //                {
                            //                    #region 更新第二条图文活动
                            //                    var entity2 = new qr_MoreActivity();
                            //                    entity2.id = alist[i].ID;//组装的多图文ID
                            //                    entity2.MA_wxTitle = Regex.Replace(row.ItemArray[15].ToString().Trim(), @"\s", ""); ;
                            //                    entity2.MA_wxImgUrl = diyhttp + Regex.Replace(row.ItemArray[17].ToString().Trim(), @"\s", "");
                            //                    entity2.MA_wxDesc = Regex.Replace(row.ItemArray[16].ToString().Trim(), @"\s", "");
                            //                    entity2.MA_wxbeforeUrl = Regex.Replace(row.ItemArray[12].ToString().Trim(), @"\s", "");
                            //                    entity2.MA_wxUrl = Regex.Replace(row.ItemArray[13].ToString().Trim(), @"\s", "");
                            //                    entity2.MA_wxafterUrl = Regex.Replace(row.ItemArray[14].ToString().Trim(), @"\s", "");
                            //                    entity2.MA_currentUrl = currentur2;//当前时间的currur2
                            //                    entity2.DateModified = DateTime.Now;
                            //                    qr_MoreActivityService.Instance.Update_Entity(entity2);
                            //                    #endregion
                            //                }
                            //                else if (alist[i].Sortnumber == 3)
                            //                {
                            //                    #region 保存第三条图文活动
                            //                    var entity3 = new qr_MoreActivity();
                            //                    //entity3.id = alist[i].ID;
                            //                    //entity3.MA_wxTitle = Par_A_wxTitle3;
                            //                    //entity3.MA_wxImgUrl = Par_A_wxImgUrl3;
                            //                    //entity3.MA_wxDesc = Par_A_wxDesc3;
                            //                    //entity3.MA_wxUrl = Par_A_wxUrl3;
                            //                    //entity3.MA_wxbeforeUrl = Par_A_wxbeforeUrl3;
                            //                    //entity3.MA_wxafterUrl = Par_A_wxafterUrl3;
                            //                    //entity3.MA_currentUrl = currenturl3;//当前时间的currurl
                            //                    //entity3.DateModified = DateTime.Now;
                            //                    //qr_MoreActivityService.Instance.Update_Entity(entity3);
                            //                    #endregion
                            //                }
                            //                else if (alist[i].Sortnumber == 4)
                            //                {
                            //                    #region 更新第四条图文活动
                            //                    var entity4 = new qr_MoreActivity();
                            //                    //entity4.id = alist[i].ID;
                            //                    //entity4.MA_wxTitle = Par_A_wxTitle4;
                            //                    //entity4.MA_wxImgUrl = Par_A_wxImgUrl4;
                            //                    //entity4.MA_wxDesc = Par_A_wxDesc4;
                            //                    //entity4.MA_wxUrl = Par_A_wxUrl4;
                            //                    //entity4.MA_wxbeforeUrl = Par_A_wxbeforeUrl4;
                            //                    //entity4.MA_wxafterUrl = Par_A_wxafterUrl4;
                            //                    //entity4.MA_currentUrl = currenturl4;//当前时间的currurl
                            //                    //entity4.DateModified = DateTime.Now;
                            //                    //qr_MoreActivityService.Instance.Update_Entity(entity4);
                            //                    #endregion
                            //                }
                            //                else if (alist[i].Sortnumber == 5)
                            //                {
                            //                    #region 更新第一条图文活动
                            //                    //var entity = new qr_Activity();
                            //                    //entity.A_Name = Par_A_Name;
                            //                    //entity.A_Desc = Par_A_Desc;
                            //                    //entity.A_Manager = Par_A_Manager;
                            //                    //entity.A_wxTitle = Par_A_wxTitle;
                            //                    //entity.A_wxImgUrl = Par_A_wxImgUrl;
                            //                    //entity.A_wxDesc = Par_A_wxDesc;
                            //                    //entity.A_wxUrl = Par_A_wxUrl;
                            //                    //entity.A_wxbeforeUrl = Par_A_wxbeforeUrl;
                            //                    //entity.A_wxafterUrl = Par_A_wxafterUrl;
                            //                    //entity.A_SaCode = parsacode;
                            //                    //entity.A_StartTime = ParStartTime;
                            //                    //entity.A_EndTime = ParEndTime;
                            //                    //entity.A_currentUrl = currenturl;//当前使用的URL
                            //                    //entity.DateModified = DateTime.Now;
                            //                    //result = qr_ActivityService.Instance.Update_Entity(entity);
                            //                    #endregion

                            //                    #region 更新第二条图文活动
                            //                    //var entity2 = new qr_MoreActivity();
                            //                    //entity2.id = alist[i].MoreActivityid;//组装的多图文ID
                            //                    //entity2.MA_wxTitle = Par_A_wxTitle2;
                            //                    //entity2.MA_wxImgUrl = Par_A_wxImgUrl2;
                            //                    //entity2.MA_wxDesc = Par_A_wxDesc2;
                            //                    //entity2.MA_wxUrl = Par_A_wxUrl2;
                            //                    //entity2.MA_wxbeforeUrl = Par_A_wxbeforeUrl2;
                            //                    //entity2.MA_wxafterUrl = Par_A_wxafterUrl2;
                            //                    //entity2.MA_currentUrl = currenturl2;//当前时间的currurl
                            //                    //entity2.DateModified = DateTime.Now;
                            //                    //qr_MoreActivityService.Instance.Add_Entity(entity2);
                            //                    #endregion

                            //                    #region 更新第三条图文活动
                            //                    //var entity3 = new qr_MoreActivity();
                            //                    //entity3.id = alist[i].MoreActivityid;
                            //                    //entity3.MA_wxTitle = Par_A_wxTitle3;
                            //                    //entity3.MA_wxImgUrl = Par_A_wxImgUrl3;
                            //                    //entity3.MA_wxDesc = Par_A_wxDesc3;
                            //                    //entity3.MA_wxUrl = Par_A_wxUrl3;
                            //                    //entity3.MA_wxbeforeUrl = Par_A_wxbeforeUrl3;
                            //                    //entity3.MA_wxafterUrl = Par_A_wxafterUrl3;
                            //                    //entity3.MA_currentUrl = currenturl3;//当前时间的currurl
                            //                    //entity3.DateModified = DateTime.Now;
                            //                    //qr_MoreActivityService.Instance.Add_Entity(entity3);
                            //                    #endregion

                            //                    #region 更新第四条图文活动
                            //                    //var entity4 = new qr_MoreActivity();
                            //                    //entity4.id = alist[i].MoreActivityid;
                            //                    //entity4.MA_wxTitle = Par_A_wxTitle4;
                            //                    //entity4.MA_wxImgUrl = Par_A_wxImgUrl4;
                            //                    //entity4.MA_wxDesc = Par_A_wxDesc4;
                            //                    //entity4.MA_wxUrl = Par_A_wxUrl4;
                            //                    //entity4.MA_wxbeforeUrl = Par_A_wxbeforeUrl4;
                            //                    //entity4.MA_wxafterUrl = Par_A_wxafterUrl4;
                            //                    //entity4.MA_currentUrl = currenturl4;//当前时间的currurl
                            //                    //entity4.DateModified = DateTime.Now;
                            //                    //qr_MoreActivityService.Instance.Add_Entity(entity4);
                            //                    #endregion

                            //                    #region 更新第五条图文活动
                            //                    var entity5 = new qr_MoreActivity();
                            //                    //entity5.id = alist[i].ID;
                            //                    //entity5.MA_wxTitle = Par_A_wxTitle5;
                            //                    //entity5.MA_wxImgUrl = Par_A_wxImgUrl5;
                            //                    //entity5.MA_wxDesc = Par_A_wxDesc5;
                            //                    //entity5.MA_wxUrl = Par_A_wxUrl5;
                            //                    //entity5.MA_wxbeforeUrl = Par_A_wxbeforeUrl5;
                            //                    //entity5.MA_wxafterUrl = Par_A_wxafterUrl5;
                            //                    //entity5.DateModified = DateTime.Now;
                            //                    //entity5.MA_currentUrl = currenturl5;//当前时间的currurl
                            //                    //qr_MoreActivityService.Instance.Update_Entity(entity5);
                            //                    #endregion
                            //                }
                            //            }
                            //        }
                            //        #endregion

                            //        #region 更新双图文活动
                            //        //var entity = new qr_Activity();
                            //        qr_Activityentity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                            //        qr_Activityentity.A_Desc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", ""); //row[3].ToString().Trim();//活动描述
                            //        qr_Activityentity.A_Manager = row[2].ToString().Trim();//负责人
                            //        qr_Activityentity.A_wxTitle = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", "");//"美赞臣产品付费试用活动";
                            //        qr_Activityentity.A_wxImgUrl = diyhttp + Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "");//"/images/20170524.jpg";//图片
                            //        qr_Activityentity.A_wxDesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", "");
                            //        qr_Activityentity.A_wxUrl = row[7].ToString().Trim();//活动中链接;
                            //        qr_Activityentity.A_wxbeforeUrl = row[6].ToString().Trim();//活动前链接;
                            //        qr_Activityentity.A_wxafterUrl = row[8].ToString().Trim();//活动后链接;
                            //        qr_Activityentity.A_SaCode = "";
                            //        qr_Activityentity.A_StartTime = ParStartTime_diy;
                            //        qr_Activityentity.A_EndTime = ParEndTime_diy;
                            //        qr_Activityentity.A_currentUrl = currenturl;//当前使用的URL
                            //        qr_Activityentity.DateModified = DateTime.Now;
                            //        result5 = qr_ActivityService.Instance.Update_Entity(qr_Activityentity);
                            //        #endregion

                            //        ComLib.LogLib.Log4NetBase.Log("有相同重复活动名称：" + qr_Activityentity.A_Name);
                            //        if (result5)
                            //        {
                            //            SuccessCount += 1;
                            //            AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "修改qr_Activity:" + qr_Activityentity.ActivityID); //记录日志
                            //        }
                            //        else
                            //        {

                            //            ErrorCount += 1;//已经添加
                            //        }
                            //        #endregion
                            //    }
                            //    else
                            //    {
                            //        #region  增加操作 去掉数据源的空格和换行符

                            //        #region 根据时间判断路径
                            //        var currenturl = "";
                            //        var currentur2 = "";
                            //        DateTime ParStartTime_diy = Convert.ToDateTime(row.ItemArray[4].ToString().Trim());//.ToString("yyyy-MM-dd HH:mm:ss")
                            //        DateTime ParEndTime_diy = Convert.ToDateTime(row.ItemArray[5].ToString().Trim());
                            //        if (DateTime.Now < ParStartTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[6].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串//Par_Diy_wxbeforeUrl;
                            //            currentur2 = Regex.Replace(row.ItemArray[12].ToString().Trim(), @"\s", "");
                            //        }
                            //        else if (DateTime.Now > ParStartTime_diy && DateTime.Now < ParEndTime_diy)
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[7].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //            currentur2 = Regex.Replace(row.ItemArray[13].ToString().Trim(), @"\s", "");
                            //        }
                            //        else
                            //        {
                            //            currenturl = Regex.Replace(row.ItemArray[8].ToString().Trim(), @"\s", "");//去掉链接URL的空字符串
                            //            currentur2 = Regex.Replace(row.ItemArray[14].ToString().Trim(), @"\s", "");
                            //        }
                            //        #endregion

                            //        #region 组装消息
                            //        var sceneid = 0;
                            //        qr_QrCodeType type = qr_QrCodeTypeService.Instance.Get_SingleEntity_byWhere(qr_QrCodeType._.QrCodeTypeID == 1000);
                            //        sceneid = type.QT_CurrentIndex.ConvertTo<int>() + 1;

                            //        #region 单图文
                            //        List<ShareMarking.Interface.extra> extra = new List<ShareMarking.Interface.extra>() { 
                            //            //new ShareMarking.Interface.extra { 
                            //            //    title = "解码萌宝成长礼，超多大奖送不停！", 
                            //            //    shortdesc = "解码萌宝成长礼，超多大奖送不停！", 
                            //            //    linkurl = (currenturl).Replace('&','$'),
                            //            //    picurl =diyhttp+ "/images/JiemaActivity.jpg"
                            //            //}
                            //            new ShareMarking.Interface.extra { 
                            //                title = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", ""),
                            //                shortdesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", ""), 
                            //                linkurl = (currenturl).Replace('&','$'),
                            //                picurl =diyhttp+ Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "")//"/images/ar.jpg"
                            //            },
                            //            new ShareMarking.Interface.extra { 
                            //                title = Regex.Replace(row.ItemArray[15].ToString().Trim(), @"\s", ""),
                            //                shortdesc = Regex.Replace(row.ItemArray[16].ToString().Trim(), @"\s", ""), 
                            //                linkurl = (currentur2).Replace('&','$'),
                            //                picurl =diyhttp+ Regex.Replace(row.ItemArray[17].ToString().Trim(), @"\s", "")//"/images/ar2.jpg"
                            //            }
                            //        };

                            //        #endregion

                            //        //string Par_A_Name = row[1].ToString().Trim() + "-" + row[0].ToString().Trim();//名称-编号
                            //        var message = new ShareMarking.Interface.message()
                            //        {
                            //            title = Par_A_Name,
                            //            remark = Par_A_Name + "的二维码",
                            //            sacode = "test",
                            //            scene_id = sceneid,
                            //            extra = extra
                            //        };
                            //        #endregion

                            //        #region vigo接口申请
                            //        var vigo = new ShareMarking.Interface.Qrcode_vigo(httpstr, signsecret);
                            //        var resultentity = vigo.CreateQrcode(message);
                            //        #endregion

                            //        #region 自增sceneid重新请求直到成功为止
                            //        while (resultentity.errcode == "12")
                            //        {
                            //            ComLib.LogLib.Log4NetBase.Log("错误信息:" + resultentity.errmsg + "/sceneid=" + sceneid);
                            //            sceneid += 1;
                            //            message.scene_id = sceneid;
                            //            resultentity = vigo.CreateQrcode(message);
                            //        }
                            //        #endregion

                            //        if (resultentity.errcode == "00")
                            //        {
                            //            string ActivityID = "";

                            //            #region 保存二维码到数据库
                            //            qr_QrCode qrcode = new qr_QrCode()
                            //            {
                            //                id = resultentity.message.id,
                            //                type = 1000,
                            //                scene_id = resultentity.message.scene_id,
                            //                sacode = resultentity.message.sacode,
                            //                title = resultentity.message.title,
                            //                remark = resultentity.message.remark,
                            //                code_url = resultentity.message.code_url,
                            //                qrcode_url = resultentity.message.qrcode_url,
                            //                addtime = resultentity.message.addtime,
                            //                status = resultentity.message.status,
                            //                isdelete = false
                            //            };
                            //            qr_QrCodeService.Instance.Add_Entity(qrcode);
                            //            #endregion

                            //            #region 保存单图文活动
                            //            var entity = new qr_Activity();
                            //            entity.A_Name = Regex.Replace(Par_A_Name.ToString().Trim(), @"\s", "");
                            //            entity.A_Desc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", "");//row[3].ToString().Trim();//活动描述
                            //            entity.A_Manager = row[2].ToString().Trim();//负责人
                            //            entity.A_wxQrCodeID = resultentity.message.id.ToString();
                            //            entity.A_wxSceneID = resultentity.message.scene_id.ToString();
                            //            entity.A_wxTitle = Regex.Replace(row.ItemArray[9].ToString().Trim(), @"\s", "");
                            //            entity.A_wxImgUrl = diyhttp + Regex.Replace(row.ItemArray[11].ToString().Trim(), @"\s", "");//图片"/images/20170524.jpg"
                            //            entity.A_wxDesc = Regex.Replace(row.ItemArray[10].ToString().Trim(), @"\s", "");
                            //            entity.A_wxUrl = row[7].ToString().Trim();//活动中链接;
                            //            entity.A_wxbeforeUrl = row[6].ToString().Trim();//活动前链接;
                            //            entity.A_wxafterUrl = row[8].ToString().Trim();//活动后链接;
                            //            entity.A_SaCode = "";
                            //            entity.A_StartTime = ParStartTime_diy;
                            //            entity.A_EndTime = ParEndTime_diy;
                            //            entity.CreateOn = DateTime.Now;
                            //            entity.isneedupdate = false;
                            //            entity.A_currentUrl = currenturl;//当前时间的currurl
                            //            entity.isSenate = 1;//有参标识
                            //            entity.A_RuleText = "MJN NC AR项目活动";//标识活动，导出图片可筛选
                            //            result2 = qr_ActivityService.Instance.Add_Entity(entity);
                            //            ActivityID = entity.ActivityID.ToString();
                            //            #endregion
                            //            #region 保存第二条图文活动
                            //            var entity2 = new qr_MoreActivity();
                            //            entity2.ActivityID = entity.ActivityID;//关联第一条图文ID
                            //            entity2.MA_Sort = 2;//当前是第二条图文信息
                            //            entity2.MA_wxTitle = Regex.Replace(row.ItemArray[15].ToString().Trim(), @"\s", ""); ;
                            //            entity2.MA_wxImgUrl = diyhttp + Regex.Replace(row.ItemArray[17].ToString().Trim(), @"\s", "");
                            //            entity2.MA_wxDesc = Regex.Replace(row.ItemArray[16].ToString().Trim(), @"\s", "");                                       
                            //            entity2.MA_wxbeforeUrl = Regex.Replace(row.ItemArray[12].ToString().Trim(), @"\s", "");
                            //            entity2.MA_wxUrl = Regex.Replace(row.ItemArray[13].ToString().Trim(), @"\s", "");
                            //            entity2.MA_wxafterUrl = Regex.Replace(row.ItemArray[14].ToString().Trim(), @"\s", "");
                            //            entity2.CreateOn = DateTime.Now;
                            //            entity2.MA_currentUrl = currentur2;//当前时间的currur2
                            //            qr_MoreActivityService.Instance.Add_Entity(entity2);
                            //            #endregion

                            //            #region 添加关联
                            //            qr_QrCodeRelate qrrelate = new qr_QrCodeRelate()
                            //            {
                            //                qr_Type = 1000,//1000是活动
                            //                qr_CodeID = resultentity.message.id,
                            //                qr_Scene_ID = resultentity.message.scene_id,
                            //                rel_Code = ActivityID,
                            //                IsDelete = false,
                            //                CreateOn = DateTime.Now,
                            //                Chre_Source = "0",//20170714需求新增子来源、指定代码字段
                            //                Appoint_Code = "0"
                            //            };
                            //            result3 = qr_QrCodeRelateService.Instance.Add_Entity(qrrelate);
                            //            #endregion

                            //            #region 更改二维码类型表
                            //            type.QT_CurrentIndex = sceneid;
                            //            type.QT_Used = type.QT_Used + 1;
                            //            type.QT_Surplus = type.QT_Surplus - 1;
                            //            result4 = qr_QrCodeTypeService.Instance.Update_Entity(type);
                            //            #endregion
                            //        }
                            //        if (result2 && result3 && result4)
                            //        {
                            //            SuccessCount += 1;
                            //        }
                            //        else
                            //        {
                            //            ErrorCount += 1;//已经添加
                            //        }
                            //        #endregion
                            //    }
                            //}
                            //else
                            //{
                            //    ErrorCount += 1;//失败条数
                            //}
                            #endregion
                        }
                    }
                    JscriptMsg("导入成功" + SuccessCount + "条，失败" + ErrorCount + "条！", "List.aspx?isSenate=true", "Success");
                }
                else
                {
                    JscriptMsg("wxcodeimport", "导入失败！请检查excel！", "", "Error");
                }
                #endregion
            }
            catch (Exception ex)
            {
                AddAdminLog(DTEnums.ActionEnum.Import.ToString(), "导入qr_Activity出错 错误为" + ex.Message + "");
                JscriptMsg("导入添加数据失败！请联系管理员！", "List.aspx?isSenate=true", "Error");
            }
        }
        #endregion   
        
    }
}